(ns ura.core (:gen-class))
(use 'ring.adapter.jetty)
(use 'ring.util.response)
(require '[flames.core :as flames])
(require '[ura.handler :as handler])
(require '[ura.config :as cfg])
(require '[taoensso.telemere :as t])
(require '[ura.migrations.migrations :as m])
(require '[ura.logo :as logo])
(require '[ura.data.Data :as data])

(defn run-dev-server [port]
  (t/log! ["URA server at port " port])
  (m/migrate "./config.edn")
  (cfg/loadConfig "config.edn")
  (def flames (flames/start! {:port 54321, :host "localhost"}))
;;; then use http://localhost:54321/flames.svg to check result
  (run-jetty handler/app { :port port})
  )


(defn -main [& args]
  (t/add-handler! :filehandler (t/handler:file {:interval :daily :path "logs/ura.log"}))
  (logo/log-logo)
  (cfg/loadConfig (first args))
  (data/init-pool)
  (run-dev-server (:serverPort cfg/cfg))
  )
